package com.geekgo.ladder.core.exception;

import com.geekgo.ladder.core.support.HttpCode;
import org.apache.commons.lang.StringUtils;
import org.springframework.ui.ModelMap;

/**
 * @author geekgo
 * @version 2016/12/22 17:38
 */
public abstract class BaseException extends RuntimeException {

    public BaseException(){

    }

    public BaseException(Throwable ex){
        super(ex);
    }

    public BaseException(String message){
        super(message);
    }

    public BaseException(String message,Throwable ex){
        super(message,ex);
    }

    public void handler(ModelMap modelMap){
        modelMap.put("httpCode",getHttpCode().value());
        if(StringUtils.isNotBlank(getMessage())){
            modelMap.put("msg",getMessage());
        }else{
            modelMap.put("msg",getHttpCode().msg());
        }
        modelMap.put("timestamp",System.currentTimeMillis());
    }

    protected abstract HttpCode getHttpCode();
}
